<?php
/**
* This file is the control panel, or "home page" for logged in users.
* It provides a listing of all upcoming reservations
*  and functionality to modify or delete them. It also
*  provides links to all other parts of the system.
* @author Nick Korbel <lqqkout13@users.sourceforge.net>
* @version 03-30-06
* @package phpScheduleIt
*
* Copyright (C) 2003 - 2007 phpScheduleIt
* License: GPL, see LICENSE
*/
function get_calendar_actual_date() {
	if (isset($_GET['date'])) {
		$date_split = explode('-', $_GET['date']);
	}
	else {
		$date_split = explode('-', date('m-d-Y', Time::getAdjustedTime(mktime(), date('H') * 60)));
	}
	
	return mktime(0,0,0, $date_split[0], $date_split[1], $date_split[2]);
}


include_once('Template.class.php');
include_once('MyCalendar.class.php');
include_once('Utility.class.php');
include_once(TEMPLATE_DIR . '/cpanel.template.php');

if (!Auth::is_logged_in()) {
    Auth::print_login_msg();	// Check if user is logged in
}

$t = new Template(Lang::getInstance()->translate('My Control Panel'));
$db = new DBEngine();

$user = new User(Auth::getCurrentID());
$isAdmin = $user->is_admin || $user->is_group_admin();

if ($isAdmin) {

	$t->printHTMLHeader();
} else {
	$t->printHTMLHeaderUser();
}
$t->printWelcome();
$t->startMain();


$is_group_admin = $user->is_group_admin();
// Break table into 2 columns, put quick links on left side and all other tables on the right
startQuickLinksCol();
showQuickLinks(Auth::isAdmin(), $is_group_admin, $t);		// Print out My Quick Links
startDataDisplayCol();

//$isAdmin = true;
$order = array('number');
if($isAdmin) {
$announcements = $db->get_announcements(mktime());

showAnnouncementTable( $announcements, $db->get_err() );

printCpanelBr();
}

// Valid order values in reservation retreival
$order = array('start_date', 'name', 'starttime', 'endtime', 'created', 'modified');
$res = $db->get_user_reservations(Auth::getCurrentID(), CmnFns::get_value_order($order), CmnFns::get_vert_order());

showReservationTable($res, $db->get_err());	// Print out My Reservations

printCpanelBr();

if($isAdmin) {
showInvitesTable($db->get_user_invitations(Auth::getCurrentID(), true), $db->get_err());
printCpanelBr();

showParticipatingTable($db->get_user_invitations(Auth::getCurrentID(), false), $db->get_err());

printCpanelBr();

if (Config::get('app','use_perms')) {
	showTrainingTable($db->get_user_permissions(Auth::getCurrentID()), $db->get_err());
}
} else {
	//echo '<iframe src="iframe_mycalendar.php?view=3" width="100%" style="height:auto"></iframe>';
	$calendarType = 3;
	if (!empty($_REQUEST['view'])) {
		$calendarType = $_REQUEST['view'];
	}
	$calendar = new MyCalendar(Auth::getCurrentID(), $calendarType, get_calendar_actual_date());
$calendar->printCalendars=false;
$calendar->print_calendar();
	
}
endDataDisplayCol();
$t->endMain();
$t->printHTMLFooter();
?>